<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/24 0024
 * Time: 10:41
 */

namespace app\common\model\mall;


use app\common\model\TimeModel;

class ItemOrderRefund extends TimeModel
{
    protected $deleteTime = 'delete_time';

    public function getRefundImagesAttr($value){
        if(!empty($value)){
            return explode(',',$value);
        }
    }
    /**
     * 关联商品
     */
    public function Goods(){
        return $this->belongsTo('app\common\model\mall\Item','item_id','id')->field('id,title,thumb,image,goods_price');
    }

    /**
     * 关联商品规格
     */
    public function GoodsSku(){
        return $this->belongsTo('app\common\model\mall\ItemSku','sku_id','id')->field('id,spec_sku_name,sku_image,goods_price');
    }

    /**
     * 关联商品子订单
     */
    public function OrderList(){
        return $this->belongsTo('app\common\model\mall\ItemOrderList','sub_order_id','id');
    }

    /**
     * 关联商品子订单
     */
    public function Order(){
        return $this->belongsTo('app\common\model\mall\ItemOrder','order_id','id');
    }
    /**
     * 关联用户信息
     */
    public function User(){
        return $this->belongsTo('app\common\model\user\WxUsers','user_id','id')->field('id,nick_name,name,phone');
    }
    public static function onAfterInsert($data){

        //$self = new static();
        $article = self::withoutGlobalScope()->find($data->id);

        $article->withoutGlobalScope()->where('id',$data->id)->save(['app_id'=>self::get_appId()]);

    }
}